package com.qy127.javaweb.dao.impl;

import com.qy127.javaweb.dao.StaffDao;
import com.qy127.javaweb.entity.Staff;
import com.qy127.javaweb.util.JDBCUtil;

import java.util.List;
import java.util.Map;

public class StaffDaoImpl implements StaffDao {
    @Override
    public List<Map<String, Object>> getStaff() {
        String sql = "select id,staffId,staffName,password,phone,idCard,address from t_staff";
        List<Map<String, Object>> maps = JDBCUtil.queryListMap(sql);
        if(maps.size()>0){
            return maps;
        }
        return null;
    }

    @Override
    public int insertStaff(Staff staff) {
        String sql = "insert  into t_staff(staffId,staffName,password,phone,idCard,address)  values(?,?,?,?,?,?)";
        int i = JDBCUtil.update(sql,staff.getStaffid(), staff.getStaffName(), staff.getPassword(), staff.getPhone(), staff.getIdCard(), staff.getAddress());
        return i;
    }

    @Override
    public int deleteStaff(Integer id) {
        String sql = "delete from t_staff where id = ?";
        int i = JDBCUtil.update(sql, id);
        return i;
    }
}
